using System;
using System.Collections.Generic;
using System.Diagnostics; 
using System.Text;

namespace PropertyGridEx
{
    public class CustomItemList
    {
        public List<CustomItem> Items = new List<CustomItem>();
        private bool _enableMultiSelect = false;
        private int _width = 300;
        private int _height = 300;

        #region Selected Items
        public List<CustomItem> SelectedItems
        {
            get 
            {

                if (Items == null) { return null; }

                List<CustomItem> selectedItems =null;

                for(int i=0;i<Items.Count;i++)
                {
                    if (Items[i].Selected)
                    {
                        if (selectedItems == null)
                        {
                            selectedItems = new List<CustomItem>();
                        }
                        selectedItems.Add(Items[i]);
                    }
                }

                return selectedItems;
            }
        }
        #endregion

        #region Selected Item
        public CustomItem SelectedItem
        {
            get
            {

                if (Items == null) { return null; }

                for (int i = 0; i < Items.Count; i++)
                {
                    if (Items[i].Selected)
                    {
                        return Items[i];
                    }
                }

                return null;
            }
        }
        #endregion

        #region Enable Multi Select 
        public bool EnableMultiSelect 
        {
            get { return _enableMultiSelect; }
        }
        #endregion

        #region Width
        public int Width
        {
            get { return _width; }
        }
        #endregion

        #region Height
        public int Height
        {
            get { return _height; }
        }
        #endregion

        #region Constructor
        public CustomItemList()
        {

        }
        #endregion

        #region Constructor
        public CustomItemList(bool enableMultiSelect)
        {
            _enableMultiSelect = enableMultiSelect;
        }
        #endregion

        #region Constructor
        public CustomItemList(bool enableMultiSelect,
                                         int height,
                                         int width)
        {
            _enableMultiSelect = enableMultiSelect;
            _height = height;
            _width = width;
        }
        #endregion

        #region Constructor
        public CustomItemList(int height,
                                         int width)
        {
            _height = height;
            _width = width;
        }
        #endregion

        #region ToString()
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            bool found = false;
     
            if (Items != null)
            {
                for(int i=0;i<Items.Count;i++)
                {
                    if (Items[i].Selected)
                    {
                         if (found)
                         {
                             sb.Append(";");
                         }
                         sb.Append(Items[i].Description);
                         found = true;
                    }
                }
            }
            
            return sb.ToString();
        }
        #endregion

    }
}
